
/*
 * -- SuperLU MT routine (version 2.0) --
 * Lawrence Berkeley National Lab, Univ. of California Berkeley,
 * and Xerox Palo Alto Research Center.
 * September 10, 2007
 *
 * Sparse matrix types and function prototypes.
 *
 */

#ifndef __SUPERLU_sSP_DEFS /* allow multiple inclusions */
#define __SUPERLU_sSP_DEFS

/*
 * File name:           pssp_defs.h
 * Purpose:             Sparse matrix types and function prototypes
 * History:
 */


#include "hnum_slucmn.h"

namespace harlinn
{
    namespace numerics
    {
        namespace SuperLU
        {
            namespace Single
            {
                typedef GlobalLU_T<float> GlobalLU_t;
                typedef pxgstrf_shared_T<GlobalLU_t> pxgstrf_shared_t;
                typedef pxgstrf_threadarg_T<pxgstrf_shared_t> psgstrf_threadarg_t;

                /* *********************
                   Function prototypes
                   *********************/

                /* ----------------
                   Driver routines 
                   ---------------*/
                void
                psgssv(int, SuperMatrix *, int *, int *, SuperMatrix *, SuperMatrix *, 
                       SuperMatrix *, int *);
                void
                psgssvx(int, superlumt_options_t *, SuperMatrix *, int *, int *,  
	                equed_t *, float *, float *, SuperMatrix *, SuperMatrix *,
	                SuperMatrix *, SuperMatrix *, 
	                float *, float *, float *, float *, superlu_memusage_t *, 
	                int *);

                /* ---------------
                   Driver related 
                   ---------------*/
                void sgsequ (SuperMatrix *, float *, float *, float *,
                                    float *, float *, int *);
                void slaqgs (SuperMatrix *, float *, float *, float, 
		                    float, float, equed_t *);
                void sgscon (char *, SuperMatrix *, SuperMatrix *,
		                    float, float *, int *);
                float sPivotGrowth(int, SuperMatrix *, int *,
			                   SuperMatrix *, SuperMatrix *);
                void sgsrfs (trans_t, SuperMatrix *, SuperMatrix *, SuperMatrix *,
		                    int *, int *, equed_t, float *, float *, SuperMatrix *,
		                    SuperMatrix *, float *, float *, Gstat_t *, int *);
                int  sp_strsv (char *, char *, char *, SuperMatrix *, SuperMatrix *,
		                      float *, int *);
                int  sp_sgemv (char *, float, SuperMatrix *, float *,
		                      int, float, float *, int);
                int  sp_sgemm (char *, int, int, int, float, SuperMatrix *, 
		                      float *, int, float, float *, int);

                /* ----------------------
                   Factorization related
                   ----------------------*/

                void
                sCreate_CompCol_Matrix(SuperMatrix *, int, int, int, float *,
		                      int *, int *, Stype_t, Dtype_t, Mtype_t);
                void
                sCreate_CompCol_Permuted(SuperMatrix *, int, int, int, float *, int *,
			                 int *, int *, Stype_t, Dtype_t, Mtype_t);
                void
                sCopy_CompCol_Matrix(SuperMatrix *, SuperMatrix *);
                void
                sCreate_Dense_Matrix(SuperMatrix *, int, int, float *, int,
		                     Stype_t, Dtype_t, Mtype_t);
                void
                sCreate_SuperNode_Matrix(SuperMatrix *, int, int, int, float *, int *, int *,
			                int *, int *, int *, Stype_t, Dtype_t, Mtype_t);
                void
                sCreate_SuperNode_Permuted(SuperMatrix *, int, int, int, float *, 
			                   int *, int *, int *, int *, int *, int *, 
			                   int *, int *, Stype_t, Dtype_t, Mtype_t);
                void
                sCopy_Dense_Matrix(int, int, float *, int, float *, int);


                void sallocateA (int, int, float **, int **, int **);
                void get_perm_c(int, SuperMatrix *, int *);
                void ssp_colorder (SuperMatrix *, int *, superlumt_options_t *,
			                 SuperMatrix *);
                int  sPresetMap (const int, SuperMatrix *, pxgstrf_relax_t *, 
		                       superlumt_options_t *, GlobalLU_t *);
                int  DynamicSetMap(const int, const int, const int, pxgstrf_shared_t*);
                void psgstrf (superlumt_options_t *, SuperMatrix *, int *, 
		                     SuperMatrix *, SuperMatrix *, Gstat_t *, int *);
                void psgstrf_init (int, fact_t, trans_t, yes_no_t, int, int, float, yes_no_t, double,
			                  int *, int *, void *, int, SuperMatrix *,
			                  SuperMatrix *, superlumt_options_t *, Gstat_t *);
                psgstrf_threadarg_t*
                psgstrf_thread_init (SuperMatrix *, SuperMatrix *, SuperMatrix *,
		                     superlumt_options_t*, pxgstrf_shared_t*, Gstat_t*, int*);
                void
                psgstrf_thread_finalize (psgstrf_threadarg_t *, pxgstrf_shared_t *,
			                 SuperMatrix *, int *, SuperMatrix *, SuperMatrix *);
                void psgstrf_finalize(superlumt_options_t *, SuperMatrix *);
                int
                psgstrf_factor_snode (const int, const int, SuperMatrix *, const float,
		                      yes_no_t *, int *, int *, int*, int*, int*, int*,
		                      float *, float *, pxgstrf_shared_t *, int *);
                void psgstrf_mark_busy_descends (int, int, int *, pxgstrf_shared_t *, int *, int *);
                int  psgstrf_snode_dfs (const int, const int, const int, const int *,
			                       const int *, const int *, int*, int *, int *,
			                       pxgstrf_shared_t *);
                int  psgstrf_snode_bmod (const int, const int, const int, const int,
				                float *, float *, GlobalLU_t*, Gstat_t*);
                void psgstrf_panel_dfs (const int, const int, const int, const int,
			                       SuperMatrix *, int*, int*, int*, int*, int*, 
			                       int*, int*, int*, int*, int*, int*, int*, int*,
			                       float*, GlobalLU_t *);
                void psgstrf_panel_bmod (const int, const int, const int, const int,
				                const int, int*, int*, int*, int*, int*, int*,
				                int*, int*, float*, float*, 
				                pxgstrf_shared_t *);
                void psgstrf_bmod1D (const int, const int, const int, const int, 
			                    const int, const int, const int, int, int,
			                    int *, int *, int *, int *, float *, float *, 
			                    GlobalLU_t *, Gstat_t *);
                void psgstrf_bmod2D (const int, const int, const int, const int,
			                    const int, const int, const int, int, int,
			                    int *, int *, int *, int *, float *, float *,
			                    GlobalLU_t *, Gstat_t *);
#ifndef _MSC_VER
                void psgstrf_bmod1D_mv2 (const int, const int, const int, const int, 
				                const int, const int, const int, int, int,
				                int *, int *, int *, int *, float *, 
				                float *, GlobalLU_t *, Gstat_t *);
                void psgstrf_bmod2D_mv2 (const int, const int, const int, const int,
				                const int, const int, const int, int, int,
				                int *, int *, int *, int *, float *, float *,
				                GlobalLU_t *, Gstat_t *);
#endif
                int  psgstrf_column_dfs(const int, const int, const int, const int,
			                       int*, int*, int*, int, int*, int*, int*, int*,
			                       int *, int *, int *, int *, pxgstrf_shared_t *);
                int  psgstrf_column_bmod(const int, const int, const int, const int, 
				                int*, int*, float*, float*,
				                pxgstrf_shared_t *, Gstat_t *);
                int  psgstrf_pivotL (const int, const int, const float, yes_no_t*,
			                    int*, int*, int*, int*, GlobalLU_t*, Gstat_t*);
                int  psgstrf_copy_to_ucol (const int, const int, const int, const int *,
				                  const int *, const int *, float*,
				                  pxgstrf_shared_t*);
                void psgstrf_pruneL (const int, const int *, const int, const int,
			                    const int *, const int *, int*, int *,
			                    GlobalLU_t *);
                void compressSUP (const int, GlobalLU_t *);
                void sreadmt (int *, int *, int *, float **, int **, int **);
                void sreadhb (int *, int *, int *, float **, int **, int **);
                void sGenXtrue (int, int, float *, int);
                void sFillRHS (trans_t, int, float *, int, 
		                      SuperMatrix *, SuperMatrix *);
                void sgstrs (trans_t, SuperMatrix *, SuperMatrix*, 
		                    int*, int*, SuperMatrix*, Gstat_t *, int *);

                /* ---------------
                   Memory related 
                   ---------------*/
                float psgstrf_MemInit (int, int, superlumt_options_t *,
			                SuperMatrix *, SuperMatrix *, GlobalLU_t *);
                float psgstrf_memory_use(const int, const int, const int);
                int  psgstrf_WorkInit (int, int, int **, float **);
                void psgstrf_SetRWork (int, int, float *, float **, float **);
                void psgstrf_WorkFree (int *, float *, GlobalLU_t *);
                int  psgstrf_MemXpand (int, int, MemType, int *, GlobalLU_t *);

                float *floatMalloc(int);
                float *floatCalloc(int);
                int  memory_usage ();
                int  superlu_sQuerySpace (int, SuperMatrix *, SuperMatrix *, int, 
				                 superlu_memusage_t *);
                int  Glu_alloc (const int, const int, const int, const MemType,
		                       int *, pxgstrf_shared_t *);

                /* -------------------
                   Auxiliary routines
                   -------------------*/
                
                void    sfill(float *, int, float);
                void    sinf_norm_error(int, SuperMatrix *, float *);
                void    snode_profile(int, int *);
                void    super_stats(int, int *, int *);
                void    panel_stats(int, int, int *, Gstat_t *);
                void    PrintSumm(char *, int, int, int);
                void    sPrintPerf(SuperMatrix *, SuperMatrix *, superlu_memusage_t *,
			                 float, float, float *, float *, char *,
			                 Gstat_t *);
                void    sCompRow_to_CompCol(int m, int n, int nnz, 
                                           float *a, int *colind, int *rowptr,
                                           float **at, int **rowind, int **colptr);


                /* -----------------------
                   Routines for debugging
                   -----------------------*/
                void    print_lu_col(int, char *, int, int, int, int *, GlobalLU_t *);
                void    print_panel_seg(int, int, int, int, int *, int *);
                void    scheck_zero_vec(int, char *, int, float *);
                void    check_repfnz(int, int, int, int *);


                void *psgstrf_thread(void *arg);

            };
        };
    };
};



#endif /* __SUPERLU_SSP_DEFS */

